package com.im.app.controller;

import com.alibaba.fastjson.JSONObject;
import com.im.app.authConfig.CurrentUser;
import com.im.app.authConfig.RequireLogin;
import com.im.app.model.User;
import com.im.app.utils.HttpUtils;
import com.im.app.utils.Response;
import com.im.app.utils.ResponseResult;
import org.jim.core.utils.JsonKit;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/translation")
public class TranslationController {

    @Value("${google.key}")
    private String key;

    @RequireLogin
    @GetMapping(value ="/google")
    public ResponseResult<Object> google(String text, String target){

        String url = "https://translation.googleapis.com/language/translate/v2?target="+target+"&q="+text+"&key="+key;
        String value = HttpUtils.sendGet(url);
        JSONObject jsonObject = JSONObject.parseObject(value);
        return Response.makeOKRsp(jsonObject);
    }


}
